package main

import (
	"fmt"
	"time"
)

func main() {
	ch := make(chan int)

	go func() {
		ch <- 1
		time.Sleep(time.Second)
		close(ch)
	}()

	go func() {
		for {
			select {
			//判断channel是否关闭
			case i, ok := <-ch:
				if !ok {
					fmt.Println("Channel closed!")
					return
				}
				fmt.Println("Received:", i)
			}
		}
	}()
	time.Sleep(time.Second * 55)
}

func handlech(channel chan int) {
	for {
		select {
		case val, ok := <-channel:
			if !ok {
				fmt.Println("channel has closeds", time.Now())
				return
			}
			time.Sleep(time.Second * 4)
			fmt.Println("recieve is :", val, time.Now())
		default:
			fmt.Println("AA")
		}
	}
}
